/*
 * Copyright 2008 Lucifer Lu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Windows.Controls;
using SilverChart.Components;
using SilverChart.Configuration;
using SilverChart.LineChart;
using SilverChart.Core.Log;
using System.Windows.Media;
using SilverChart.DotChart;
using SilverChart.BarChart;

namespace SilverChart {
    /// <summary>
    /// Description of ChartComposite.
    /// </summary>
    public partial class ChartComposite : CompositeChartWidget {
        private static Logger logger = Logger.GetLogger(typeof(ChartComposite).FullName);
        public ChartComposite()
            : base() {
            InitializeComponent();
            WidgetsManager.AddComponent(this);

            if (Configurations.Instance.Title != null) {
                Children.Add(new ChartTitleComponent(Configurations.Instance.Title,
                    Configurations.Instance.TitleColor));
            }

            foreach (Element element in Configurations.Instance.Elements) {
                ChartBase chart = null;
                switch (element.ChartType) {
                    case ChartType.Line:
                        chart = new LineChartModel(element);
                        break;
                    case ChartType.Dot:
                        chart = new DotChartModel(element);
                        break;
                    case ChartType.Bar:
                        chart = new BarChartModel(element);
                        break;
                    case ChartType.Pie:
                        //chart = new PieChartModel(element);
                        break;
                }
                if (chart != null) {
                    Children.Add(chart);
                }
            }

            logger.Debug("Init Legends Component:" + Configurations.Instance.Legend.ToString());
            Children.Add(new LegendsComponent(Configurations.Instance.Legend));
        }

        public override string WidgetName {
            get {
                return "Chart Composite";
            }
        }
        private const String _ChartTitle = "ChartTitle";

        internal virtual void BringChartToFront(ChartBase chart) {
            if (Children.Contains(chart)) {
                Children.Remove(chart);
                Children.Insert(Children.Count-1, chart);
            }
        }
    }
}
